function loginbox(){
	var loginBox = $('#login-box');
    loginBox.fadeIn("slow");
    $('body').append('<div id="over"></div>');
    $('#over').fadeIn(300);
    $(document).on('click', "a.close, #over", function() { 
        $('#over, .login').fadeOut(300 , function() {
            document.getElementById('login-box').style = "position:absolute;";
            $('#over').remove();  
        }); 
        return false;
    });
    return false;
}

function dangnhap(){
    var username = $("#username").val();
    var password = $("#password").val();
    var url = window.location.href;
    xmlhttp = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 && xmlhttp.status == 200) {
            if (xmlhttp.responseText.length == 5) {
                $("#rs").html("Đăng nhập thành công!");
                window.setTimeout(function(){
                            window.location=url;
                        },1000);
            } else {
                $("#rs").html(xmlhttp.responseText);
            }
        }
    }
    var data = "username="+username+"&password="+password;
    xmlhttp.open("POST","user/login.php",true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.send(data);
}
function registrybox(){
    var regbox = $('#register-box');
    regbox.fadeIn("fast");
    $('body').append('<div id="over"></div>');
    $('#over').fadeIn(10);
    $(document).on('click', "a.rclose, #over", function() { 
        $('#over, .registry').fadeOut(300 , function() {
            document.getElementById('registry-box').style = "position:absolute;";
            $('#over').remove();  
        }); 
        return false;
    });
    return false;
}
function dangky(){
    var url = window.location.href;
    xmlhttp = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 && xmlhttp.status == 200) {
            if (xmlhttp.responseText.length == 4) {
                $("#reg_error").html("Đăng ký thành công! Đăng nhập ngay bây giờ!");
                window.setTimeout(function(){
                            window.location=url;
                        },1000);
            } else {
                $("#reg_error").html(xmlhttp.responseText);
            }
        }
    }
    xmlhttp.open("POST","user/registry.php",true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.send($(".registry-content").serialize());
}
